<div id="main">
<div id="contents_stat">
<form method="post" action="#" name="filters">
<fieldset id="rulefieldset">
<legend>
    <label sid="qos.ruledownload_add"></label>
</legend>
<div class="frame_tab_layer">
<table class="cmenutitle" cellspacing="0" cellpadding="0" border="0" width="100%">
<tbody>
<tr>
    <td class="frame_tab_left">
        <label for="nameid">
            <label sid="qos.classifier_name"></label>
        </label>
    </td>
    <td class="frame_tab_right">
        <input id="nameid" type="text" maxlength="15" size="17" name="nameid">
    </td>
</tr>
<tr>
    <td class="frame_tab_left">
        <label for="groupid">
            <label sid="qos.classifier_group"></label>
        </label>
    </td>
    <td class="frame_tab_right">
        <select id="groupid" name="groupid">
            <option value="5" sid="qos.Highest"></option>
            <option value="2" sid="qos.High"></option>
            <option value="6" sid="qos.Default"></option>
            <option value="1" sid="qos.Low"></option>
        </select>
    </td>
</tr>
<tr>
    <td class="frame_tab_left">
        <label for="destipid">
            <label sid="qos.classifier_dip"></label>
        </label>
    </td>
    <td class="frame_tab_right">
        <input id="destipid" type="text" maxlength="15" size="17" name="destipid"/>
        <span class="x-form-tip" id="destipidTip"></span>
    </td>
</tr>
<tr>
    <td class="frame_tab_left">
        <label for="sourceipid">
            <label sid="qos.classifier_sip"></label>
        </label>
    </td>
    <td class="frame_tab_right">
        <input id="sourceipid" type="text" maxlength="15" size="17" name="sourceipid"/>
        <span class="x-form-tip" id="sourceipidTip"></span>
    </td>
</tr>
<tr>
    <td class="frame_tab_left">
        <label for="packetlengthid">
            <label sid="qos.classifier_pktlen"></label>
        </label>
    </td>
    <td class="frame_tab_right">
        <input id="startlengthid" type="text" maxlength="6" size="6" name="startlengthid">
        -
        <input id="finallengthid" type="text" maxlength="6" size="6" name="finallengthid">
    </td>
</tr>
<tr>
    <td class="frame_tab_left">
        <label for="dscpid">
            <label sid="qos.classifier_dscp"></label>
        </label>
    </td>
    <td class="frame_tab_right">
        <select id="dscpid" name="dscpid">
            <option value="">None</option>
            <option value="BE">BE (Default)</option>
            <option value="AF11">AF11</option>
            <option value="AF12">AF12</option>
            <option value="AF13">AF13</option>
            <option value="AF21">AF21</option>
            <option value="AF22">AF22</option>
            <option value="AF23">AF23</option>
            <option value="AF31">AF31</option>
            <option value="AF32">AF32</option>
            <option value="AF33">AF33</option>
            <option value="AF41">AF41</option>
            <option value="AF42">AF42</option>
            <option value="AF43">AF43</option>
            <option value="EF">EF</option>
        </select>
    </td>
</tr>
<tr>
    <td class="frame_tab_left">
        <label for="protocalid">
            <label sid="qos.classifier_proto"></label>
        </label>
    </td>
    <td class="frame_tab_right">
        <select id="protocalid" onchange="changeProtocal();" name="protocalid">
            <option value="">None</option>
            <option value="TCP">TCP</option>
            <option value="UDP">UDP</option>
            <option value="ICMP">ICMP</option>
            <option value="Application">Application</option>
        </select>
    </td>
</tr>
<tr id="trdestportid">
    <td class="frame_tab_left">
        <label for="destportid">
            <label sid="qos.classifier_dport"></label>
        </label>
    </td>
    <td class="frame_tab_right">
        <input id="startdestportid" type="text" maxlength="6" size="6" name="startdestportid">
        -
        <input id="finaldestportid" type="text" maxlength="6" size="6" name="finaldestportid">
    </td>
</tr>
<tr id="trsourceportid">
    <td class="frame_tab_left">
        <label for="sourceportid">
            <label sid="qos.classifier_sport"></label>
        </label>
    </td>
    <td class="frame_tab_right">
        <input id="startsourceportid" type="text" maxlength="6" size="6" name="startsourceportid">
        -
        <input id="finalsourceportid" type="text" maxlength="6" size="6" name="finalsourceportid">
    </td>
</tr>
<tr id="trapplicationid">
    <td class="frame_tab_left">
        <label for="applicationid">
            <label sid="qos.classifier_l7"></label>
        </label>
    </td>
    <td class="frame_tab_right">
        <select id="applicationid" name="applicationid">
            <option value="">None</option>
            <option value="sip">SIP</option>
            <option value="rtp">RTP</option>
            <option value="teamfortress2">Team Fortress 2</option>
            <option value="edonkey">eDonkey2000</option>
            <option value="cvs">CVS</option>
            <option value="rdp">RDP</option>
            <option value="nbns">NBNS</option>
            <option value="DNS">Domain Name System</option>
            <option value="quake-halflife">HL1, Quake, CS</option>
            <option value="x11">X Windows Version 11</option>
            <option value="xboxlive">XBox Live</option>
            <option value="halflife2-deathmatch">Half</option>
            <option value="imesh">iMesh</option>
            <option value="smb">Samba/SMB</option>
            <option value="armagetron">Armagetron Advanced</option>
            <option value="replaytv-ivs">ReplayTV Internet Video Sharing</option>
            <option value="counterstrike-source">Counterstrike (using the new Source engine)</option>
            <option value="ssh">SSH</option>
            <option value="jabber">Jabber (XMPP)</option>
            <option value="ssl">SSL and TLS</option>
            <option value="subversion">Subversion</option>
            <option value="bittorrent">Bittorrent</option>
            <option value="tor">Tor</option>
            <option value="ftp">FTP</option>
            <option value="tsp">TSP</option>
            <option value="ssdp">SSDP</option>
            <option value="fasttrack">FastTrack</option>
            <option value="http-rtsp">RTSP in HTTP</option>
            <option value="whois">Whois</option>
            <option value="nimda">Nimda</option>
            <option value="validcertssl">Valid Cert. SSL</option>
            <option value="gnucleuslan">GnucleusLAN</option>
            <option value="vnc">VNC</option>
            <option value="h323">H.323</option>
            <option value="hddtemp">hddtemp</option>
            <option value="dhcp">DHCP</option>
            <option value="ipp">IP printing</option>
            <option value="msnmessenger">MSN Messenger</option>
            <option value="irc">IRC</option>
            <option value="doom3">Doom 3</option>
            <option value="dayofdefeat-source">Day of Defeat: Source</option>
            <option value="telnet">Telnet</option>
            <option value="aimwebcontent">AIM web content</option>
            <option value="xunlei">Xunlei</option>
            <option value="soribada">Soribada</option>
            <option value="skypetoskype">Skype to Skyp</option>
            <option value="gnutella">Gnutella</option>
            <option value="shoutcast">Shoutcast and Icecast</option>
            <option value="chikka">Chikka</option>
            <option value="ciscovpn">Cisco VPN</option>
            <option value="ventrilo">Ventrilo</option>
            <option value="applejuice">Apple Juice</option>
            <option value="http">HTTP</option>
            <option value="pop3">POP3</option>
            <option value="teamspeak">TeamSpeak</option>
            <option value="radmin">Famatech Remote Administrator</option>
            <option value="rtsp">RTSP</option>
            <option value="soulseek">Soulseek</option>
            <option value="thecircle">The Circle</option>
            <option value="mute">MUTE</option>
            <option value="citrix">Citrix ICA</option>
            <option value="ncp">NCP</option>
            <option value="directconnect">Direct Connect</option>
            <option value="subspace">Subspace</option>
            <option value="code_red">Code Red</option>
            <option value="cimd">CIMD</option>
            <option value="battlefield1942">Battlefield 1942</option>
            <option value="imap">IMAP</option>
            <option value="ares">Ares</option>
            <option value="qq">Tencent QQ Protocol</option>
            <option value="aim">AIM</option>
            <option value="freenet">Freenet</option>
            <option value="ntp">(S)NTP</option>
            <option value="yahoo">Yahoo messenger</option>
            <option value="bgp">BGP</option>
            <option value="openft">OpenFT</option>
            <option value="worldofwarcraft">World of Warcraft</option>
            <option value="ident">Ident</option>
            <option value="gkrellm">Gkrellm</option>
            <option value="socks">SOCKS Version 5</option>
            <option value="smtp">SMTP</option>
            <option value="mohaa">Medal of Honor Allied Assault</option>
            <option value="gopher">Gopher</option>
            <option value="napster">Napster</option>
            <option value="snmp">SNMP</option>
            <option value="nntp">NNTP</option>
            <option value="skypeout">Skype to phone</option>
        </select>
    </td>
</tr>
<tr>
    <td class="frame_tab_left">
        <label for="remarkid">
            <label sid="qos.classifier_remark"></label>
        </label>
    </td>
    <td class="frame_tab_right">
        <select id="remarkid" name="remarkid">
            <option value="N/A" sid="qos.classifier_close"></option>
            <option id="QoSClassifierAutoStr" value="Auto" sid="qos.classifier_auto"></option>
            <option value="BE">BE (000000)</option>
            <option value="AF11">AF11</option>
            <option value="AF12">AF12</option>
            <option value="AF13">AF13</option>
            <option value="AF21">AF21</option>
            <option value="AF22">AF22</option>
            <option value="AF23">AF23</option>
            <option value="AF31">AF31</option>
            <option value="AF32">AF32</option>
            <option value="AF33">AF33</option>
            <option value="AF41">AF41</option>
            <option value="AF42">AF42</option>
            <option value="AF43">AF43</option>
            <option value="EF">EF (101110)</option>
        </select>
    </td>
</tr>
<tr>
    <td class="frame_tab_center" colspan="2"></td>
</tr>
<tr>
    <td class="frame_tab_center" colspan="2">
        <input id="save_button" class="button" type="button" name="save_button" sid="sbutton.add">
    </td>
</tr>
</tbody>
</table>
</div>
</fieldset>
<fieldset id="qosruleid">
    <legend>
        <label sid="qos.rule_title"></label>
    </legend>
    <div class="frame_tab_layer">
        <table id="qosruletable" class="cmenutitle" cellspacing="0" cellpadding="0" border="0" width="100%"> </table>
    </div>
</fieldset>
</form>
</div>
</div>
<script type="text/javascript" src="js/libTable.js"></script>
<script type="text/javascript">
$(document).ready(function(){
    var isSave=false;
    $.formValidator.initConfig({debug:false,submitOnce:true,submitButtonID:"save_button",
        onError:function(msg, obj, errorlist) {

        },
        onSuccess:function(){
            virtual_add();
        }
    });
    $("#destipid").formValidator({
        onFocus:errmsg.Info9
    }).regexValidator({
                regExp:regexEnum.notempty,
                onError:errmsg.Info3
            }).regexValidator({
                regExp:regexEnum.ip4,
                onError:errmsg.Info1
            });

    $("#sourceipid").formValidator({
        onFocus:errmsg.Info9
    }).regexValidator({
                regExp:regexEnum.notempty,
                onError:errmsg.Info3
            }).regexValidator({
                regExp:regexEnum.ip4,
                onError:errmsg.Info1
            });
    $("#destipid,#sourceipid").unFormValidator(true);
    $("#destipid,#sourceipid").bind("blur",function(){
        if($(this).val()==""){
            if(!isSave){
                $(this).unFormValidator(true);
            }
        }
    });
    $("#destipid,#sourceipid").bind("click",function(){
        isSave =false;
        $(this).unFormValidator(false);
    });
    $("#save_button").bind("mouseover",function(){
        if($("#destipid").val()=="" && $("#sourceipid").val()==""){
            $("#destipid").unFormValidator(false);

        }
    });
    $("#save_button").bind("click",function(){
        isSave =true;
    })
});
function load_html(){	
	var sendtext='&id=2120&id=2144';
	DataRequest("get_json",sendtext,function(data){
		if(data["id2120"]=="0"){
			$("#upload").hide();
			$("#download").hide();
		}else if(data["id2120"]=="1"){
			$("#upload").show();
			$("#download").show();
		}else if(data["id2120"]=="2"){
			$("#upload").show();
			$("#download").hide();
		}else if(data["id2120"]=="3"){
			$("#upload").hide();
			$("#download").show();
		}
		var tmparray2 = strToJSON(data["id2144"]);
		//if(tmparray2!=""){
			virtual_data2 = tmparray2;
		  virtual_paint_list(tmparray2);
		//}
		changeProtocal();
  		 
  });
}

	function setEnable(){
		for(var i=1;i<=6;i++){
			$("#id212"+i).removeAttr("disabled");
		}
	}
	function setDisable(){
		for(var i=1;i<=6;i++){
			$("#id212"+i).attr({"disabled":"disabled"});
		}
	}
	
	
	function changeProtocal(){
		if($.trim($("#protocalid").val())=="TCP" || $.trim($("#protocalid").val())=="UDP"){
			$("#trdestportid").show();
			$("#trsourceportid").show();
			$("#trapplicationid").hide();
		}else if($.trim($("#protocalid").val())=="ICMP"){
			$("#trdestportid").hide();
			$("#trsourceportid").hide();
			$("#trapplicationid").hide();
		}else if($.trim($("#protocalid").val())=="Application"){
			$("#trdestportid").hide();
			$("#trsourceportid").hide();
			$("#trapplicationid").show();
		}else{
			$("#trdestportid").hide();
			$("#trsourceportid").hide();
			$("#trapplicationid").hide();
			}
	}
	
	function selectDRR(){
		$("#tdid2127").show();
		$("#tdid2128").show();
		$("#tdid2129").show();
		$("#tdid2130").show();
		$("#tdid2135").show();
		$("#tdid2136").show();
		$("#tdid2137").show();
		$("#tdid2138").show();
	}
	
	function selectSPQ(){
		$("#tdid2127").hide();
		$("#tdid2128").hide();
		$("#tdid2129").hide();
		$("#tdid2130").hide();
		$("#tdid2135").hide();
		$("#tdid2136").hide();
		$("#tdid2137").hide();
		$("#tdid2138").hide();
	}
	
	function selectDRRSPQ(){
		$("#tdid2127").hide();
		$("#tdid2128").hide();
		$("#tdid2129").show();
		$("#tdid2130").show();
		$("#tdid2135").hide();
		$("#tdid2136").hide();
		$("#tdid2137").show();
		$("#tdid2138").show();
	}



	var virtual_data2 = new Array();
	var old_virtual2=0;
	load_html();

	function virtual_add(){
		  var nameid = $("#nameid").val();
		  var groupid = $("#groupid").val();
		  var protocalid = $("#protocalid").val();
		  var destipid = $("#destipid").val();
		  var sourceipid = $("#sourceipid").val();
		  var startlengthid = $("#startlengthid").val();
		  var finallengthid = $("#finallengthid").val();
		  var startdestportid = $("#startdestportid").val();
		  var finaldestportid = $("#finaldestportid").val();
		  var startsourceportid = $("#startsourceportid").val();
		  var finalsourceportid = $("#finalsourceportid").val();
		  var applicationid = $("#applicationid").val();
		  var dscpid = $("#dscpid").val();
		  var remarkid = $("#remarkid").val();
		  
		  	if($("#save_button").val()==sbutton.modify){
			  	virtual_data2[old_virtual2][0]=nameid;
			  	virtual_data2[old_virtual2][1]=groupid;
			  	virtual_data2[old_virtual2][4]=protocalid;
			  	virtual_data2[old_virtual2][5]=destipid;
			  	virtual_data2[old_virtual2][6]=sourceipid;
			  	virtual_data2[old_virtual2][7]=startlengthid;
			  	virtual_data2[old_virtual2][8]=finallengthid;
			  	virtual_data2[old_virtual2][9]=startdestportid;
			  	virtual_data2[old_virtual2][10]=finaldestportid;
			  	virtual_data2[old_virtual2][11]=startsourceportid;
			  	virtual_data2[old_virtual2][12]=finalsourceportid;
			  	virtual_data2[old_virtual2][13]=applicationid;
			  	virtual_data2[old_virtual2][14]=dscpid;
			  	virtual_data2[old_virtual2][16]=remarkid;
			  }else{
			  	var newarray= new Array();
			  	newarray[0]=nameid;
			  	newarray[1]=groupid;
			  	newarray[2]=1;
			  	newarray[3]='';
			  	newarray[4]=protocalid;
			  	newarray[5]=destipid;
			  	newarray[6]=sourceipid;
			  	newarray[7]=startlengthid;	  	
			  	newarray[8]=finallengthid;
			  	newarray[9]=startdestportid;
			  	newarray[10]=finaldestportid;
			  	newarray[11]=startsourceportid;
			  	newarray[12]=finalsourceportid;
			  	newarray[13]=applicationid;
			  	newarray[14]=dscpid;
			  	newarray[15]="";
			  	newarray[16]=remarkid;
			  	virtual_data2.push(newarray);
			  	$("#save_button").val(sbutton.add);
			  }

		var resultStr = JSONTostr(virtual_data2);	
       var settext='&id2144='+resultStr;
		  submitform(modules["set_data"],settext,"qosdownrule_main_load");
		  load_html();
	}
	
	function virtual_paint_list(data){
	  var data_new=new Array();
	  var j=0;
	  for(var i=0;i<data.length;i++){
	 	var ID = parseInt(parseInt(i)+1);
	  var nameid=data[i][0];
	  var groupid=data[i][1];
	  var protocalid=data[i][4];
		var destipid=data[i][5];
		var sourceipid=data[i][6];
		var startlengthid=data[i][7];
		var finallengthid=data[i][8];
		var startdestportid=data[i][9];
		var finaldestportid=data[i][10];
		var startsourceportid=data[i][11];
		var finalsourceportid=data[i][12];
		var applicationid=data[i][13];
		var dscpid=data[i][14];
		var remarkid=data[i][16];
		
		var groupname;
		if(groupid=="5"){
			groupname="Highest";
		}else if(groupid=="2"){
			groupname="High";
		}else if(groupid=="6"){
			groupname="Default";
		}else if(groupid=="1"){
			groupname="Low";
		}
		
		var info="";
		if(protocalid!=""){
			info+="Protocal:"+protocalid+",<br>";
		}else{
			info+=",";
		}
		if(destipid!=""){
			info+="Dest IP Address:"+destipid+",<br>";
		}else{
			info+=",";
		}
		if(sourceipid!=""){
			info+="Src IP Address:"+sourceipid+",<br>";
		}else{
			info+=",";
		}
		if(startlengthid!=""){
			info+="Packet Length:"+startlengthid+"-"+finallengthid+",<br>"
		}else{
			info+=",";
		}
		if(startdestportid!=""){
			info+="Dest Port:"+startdestportid+"-"+finaldestportid+",<br>";
		}else{
			info+=",";
		}
		if(startsourceportid!=""){
			info+="Source Port:"+startsourceportid+"-"+finalsourceportid+",<br>";
		}else{
			info+=",";
		}
		
		if(applicationid!=""){
			info+="Application:"+applicationid+",<br>";
		}else{
			info+=",";
		}
		
		if(dscpid!=""){
			info+="DSCP:"+dscpid+",<br>";
		}else{
			info+=",";
		}
		
		if(remarkid!=""){
			info+="Remark DSCP as:"+remarkid;
		}
	data_new.push({ID:ID,nameid:nameid,groupname:groupname,info:info});
	  j = i;
	 }
	 var fun_arr2 = [{type:"modify",name:"virtual_change2"},{type:"del",name:"virtual_del2"}];
	 var tab = new libTable(new Array(qos.rule_no,qos.rule_name,qos.rule_prio,qos.rule_info,msg.op),data_new,1,10);
	 print_table("qosruletable",tab,fun_arr2, true);
}

function virtual_change2(id,nameid,groupname,info)
{
 obj = virtual_data2[parseInt(id)-1];
 old_virtual2 = parseInt(id)-1;
 with(obj){
  $("#nameid").val(nameid);
  if(groupname=="Highest"){
  	listselect("groupid",5);
  	
  }else if(groupname=="High"){
  	listselect("groupid",2);
  	
  }else if(groupname="Default"){
  	listselect("groupid",6);
  }else if(groupname=""){
  	listselect("groupid",1);
  }
  
  var infos=info.split(",");
  if(infos[0]!=""&&infos[0].indexOf(":")>=0){
  	var temp=infos[0].split(":");
  	$("#protocalid").val(temp[1].replace("<br>",""));
  }else{
  	$("#protocalid").val("");
  }
  if(infos[1]!=""&&infos[1].indexOf(":")>=0){
  	var temp=infos[1].split(":");
  	$("#destipid").val(temp[1].replace("<br>",""));
  }else{
  	$("#destipid").val("");
  }
  if(infos[2]!=""&&infos[2].indexOf(":")>=0){
  	var temp=infos[2].split(":");
  	$("#sourceipid").val(temp[1].replace("<br>",""));
  }else{
  	$("#sourceipid").val("");
  }
  if(infos[3]!=""&&infos[3].indexOf(":")>=0){
  	var temp=infos[3].split(":");
  	var two=temp[1].split("-");
  	$("#startlengthid").val(two[0]);
  	$("#finallengthid").val(two[1].replace("<br>",""));
  }else{
  	$("#startlengthid").val("");
  	$("#finallengthid").val("");
  }
  if(infos[4]!=""&&infos[4].indexOf(":")>=0){
  	var temp=infos[4].split(":");
  	var two=temp[1].split("-");
  	$("#startdestportid").val(two[0]);
  	$("#finaldestportid").val(two[1].replace("<br>",""));
  }else{
  	$("#startdestportid").val("");
  	$("#finaldestportid").val("");
  }
  if(infos[5]!=""&&infos[5].indexOf(":")>=0){
  	var temp=infos[5].split(":");
  	var two=temp[1].split("-");
  	$("#startsourceportid").val(two[0]);
  	$("#finalsourceportid").val(two[1].replace("<br>",""));
  }else{
  	$("#startsourceportid").val("");
  	$("#finalsourceportid").val("");
  }
  if(infos[6]!=""&&infos[6].indexOf(":")>=0){
  	var temp=infos[6].split(":");
  	$("#applicationid").val(temp[1].replace("<br>",""));
  }else{
  	$("#applicationid").val("");
  	}
  if(infos[7]!=""&&infos[7].indexOf(":")>=0){
  	var temp=infos[7].split(":");
  	$("#dscpid").val(temp[1].replace("<br>",""));
  }else{
  	$("#dscpid").val("");
  	}
  if(infos[8]!=""&&infos[8].indexOf(":")>=0){
  	var temp=infos[8].split(":");
  	$("#remarkid").val(temp[1].replace("<br>",""));
  }else{
  	$("#remarkid").val("");
  	}
  changeProtocal();
 }
 Modify_button();
}


function virtual_del2(id,nameid,groupname,info){
 if(confirm(msg.confirm_del)){
//show_message("del",msg.deleting);
 virtual_data2[parseInt(id)-1] = [];
 var resultStr = JSONTostr(virtual_data2);
  var settext='&id2144='+resultStr;
  submitform(modules["set_data"],settext,"qosdownrule_main_load");
  load_html();
 }
}


</script>
